package com.ktjiaotu;

import com.ktjiaotu.pojo.Person;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * @Author: DABINGCHNEGJIAO
 * @CreateTime: 2025-06-03
 * @Description:
 * @Version: 1.0
 */
public class GetClassFieldsInfo {
    public static void main(String[] args) {
        Field[] fields = Person.class.getDeclaredFields();
        System.out.println("=======属性展示=======");
        for (Field field : fields) {
            System.out.println("属性名:" + field.getName());
            System.out.println("属性类型:" + field.getType().getName());
            System.out.println("访问修饰符:");
            int modifiers = field.getModifiers();
            if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC) {
                System.out.println("访问修饰符是:public");
            } else if ((modifiers & Modifier.PROTECTED) == Modifier.PROTECTED) {
                System.out.println("<访问修饰符是>:protected");
            } else if ((modifiers & Modifier.PRIVATE) == Modifier.PRIVATE) {
                System.out.println("<访问修饰符是>:private");
            } else {
                System.out.println("访问修饰符是 default(package)");
            }
            if ((modifiers & Modifier.STATIC) == Modifier.STATIC) {
                System.out.println("修饰符是:static");
            }
            if ((modifiers & Modifier.FINAL) == Modifier.FINAL) {
                System.out.println("修饰符是:final");
            }
            System.out.println("========================");
        }
    }
}
